home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 November / SGI Freeware 1999 November - Disc 1.iso / dist / fw_readline.idb / usr / freeware / share / readline / rltest.c.z / rltest.c
C/C++ Source or Header  |  1999-04-16  |  1KB  |  68 lines

  1. /* **************************************************************** */
  2. /*                                    */
  3. /*            Testing Readline                */
  4. /*                                    */
  5. /* **************************************************************** */
  6.  
  7. /*
  8.  * Remove the next line if you're compiling this against an installed
  9.  * libreadline.a
  10.  */
  11. #define READLINE_LIBRARY
  12.  
  13. #if defined (HAVE_CONFIG_H)
  14. #include <config.h>
  15. #endif
  16.  
  17. #include <stdio.h>
  18. #include <sys/types.h>
  19. #include "readline.h"
  20. #include "history.h"
  21.  
  22. extern HIST_ENTRY **history_list ();
  23.  
  24. main ()
  25. {
  26.   char *temp, *prompt;
  27.   int done;
  28.  
  29.   temp = (char *)NULL;
  30.   prompt = "readline$ ";
  31.   done = 0;
  32.  
  33.   while (!done)
  34.     {
  35.       temp = readline (prompt);
  36.  
  37.       /* Test for EOF. */
  38.       if (!temp)
  39.     exit (1);
  40.  
  41.       /* If there is anything on the line, print it and remember it. */
  42.       if (*temp)
  43.     {
  44.       fprintf (stderr, "%s\r\n", temp);
  45.       add_history (temp);
  46.     }
  47.  
  48.       /* Check for `command' that we handle. */
  49.       if (strcmp (temp, "quit") == 0)
  50.     done = 1;
  51.  
  52.       if (strcmp (temp, "list") == 0)
  53.     {
  54.       HIST_ENTRY **list;
  55.       register int i;
  56.  
  57.       list = history_list ();
  58.       if (list)
  59.         {
  60.           for (i = 0; list[i]; i++)
  61.         fprintf (stderr, "%d: %s\r\n", i, list[i]->line);
  62.         }
  63.     }
  64.       free (temp);
  65.     }
  66.   exit (0);
  67. }
  68.